﻿using DynamicViewFormApp.Setting;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DynamicViewFormApp.Component.Handler
{
    class ToolStripHandler
    {
        internal static void FontStyleBold_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        if (font.Bold)
                        {
                            rtb.SelectionFont = new Font(font, FontStyle.Regular);
                        }
                        else
                        {
                            rtb.SelectionFont = new Font(font, FontStyle.Bold);
                        }
                    }
                }
            }
        }
        internal static void FontStyleItalic_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        if (font.Italic)
                        {
                            rtb.SelectionFont = new Font(font, FontStyle.Regular);
                        }
                        else
                        {
                            rtb.SelectionFont = new Font(font, FontStyle.Italic);
                        }
                    }
                }
            }
        }

        internal static void FontSizeDown_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        rtb.SelectionFont = new Font(font.FontFamily, font.Size - 1);
                    }
                }
            }
        }
        internal static void FontSizeContent_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    rtb.SelectionFont = FontSetting.FontContent;
                }
            }
        }
        internal static void FontSizeHeader1_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    rtb.SelectionFont = FontSetting.FontHeader1;
                }
            }
        }

        internal static void FontSizeHeader2_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        rtb.SelectionFont = FontSetting.FontHeader2;
                    }
                }
            }
        }

        internal static void FontSizeHeader3_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        rtb.SelectionFont = FontSetting.FontHeader3;
                    }
                }
            }
        }
        internal static void FontSizeHeader4_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        rtb.SelectionFont = FontSetting.FontHeader4;
                    }
                }
            }
        }
        internal static void FontSizeHeader5_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        rtb.SelectionFont = FontSetting.FontHeader5;
                    }
                }
            }
        }
        internal static void FontSizeHeader6_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        rtb.SelectionFont = FontSetting.FontHeader6;
                    }
                }
            }
        }


        internal static void FontSizeUp_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        rtb.SelectionFont = new Font(font.FontFamily, font.Size + 1);
                    }
                }
            }
        }

        internal static void FontStyleUnderline_Click(object sender, EventArgs e)
        {
            RichTextBox rtb = PublicVariable.CurrentRichTextBox;
            if (rtb != null)
            {
                // Ensure that text is currently selected in the text box.   
                if (rtb.SelectedText.Length > 0)
                {
                    Font font = rtb.SelectionFont;
                    if (font != null)
                    {
                        if (font.Underline)
                        {
                            rtb.SelectionFont = new Font(font, FontStyle.Regular);
                        }
                        else
                        {
                            rtb.SelectionFont = new Font(font, FontStyle.Underline);
                        }
                    }
                }
            }
        }


    }
}
